package com.naiterui.ehp.bp.utils.thread;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.springframework.core.task.TaskExecutor;

import com.naiterui.ehp.bp.utils.context.SpringContextHolder;

/**
 * 异步线程池实现
 *  此工具类不能在 org.springframework.beans.factory.InitializingBean#afterPropertiesSet() 中使用
 * @author Gaoll
 * @since HZD-1.0.0
 */
@SuppressWarnings("unused")
public final class ThreadPoolUtil {

    private static TaskExecutor executor = SpringContextHolder.getBean(TaskExecutor.class);

    private static ScheduledExecutorService scheduledExecutorService = SpringContextHolder.getBean(ScheduledExecutorService.class);

    public static void execute(Runnable runnable) {
        executor.execute(runnable);
    }

    public static void schedule(Runnable command, long delay, TimeUnit unit) {
        scheduledExecutorService.schedule(command, delay, unit);
    }

}